<%--
  Created by IntelliJ IDEA.
  User: JIAHANG
  Date: 2023/1/30
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物页</title>
    <link rel="stylesheet" href="/untitled01_war_exploded/css/product.css" />
    <script type="text/javascript" src="/untitled01_war_exploded/js/product.js"></script>
    <script type="text/javascript" src="/untitled01_war_exploded/js/shopp.js"></script>
    <script type="text/javascript">
        //var td=table.rows[tr下标，从0开始'].cells[列下标，从0开始'];
        window.onload = function () {
                 var tableLine = document.getElementById("number");
                for (var i = 0; i < tableLine.rows.length; i++) {
                tableLine.rows[i].cells[0].innerHTML = (i + 1);
                   }
            }
    </script>
    <script type="text/javascript" src="/untitled01_war_exploded/js/messager.js"></script>
</head>
<body>
<%--<%@include file="/JSP/Navbar.jsp"%>--%>
<div class="foot" id="foot">
<%--    <label class="fl select-all"><input type="checkbox" class="check-all check"/>&nbsp;全选</label>--%>
<%--    <a class="fl delete" id="deleeAll" href="././JSP/Shopping.jsp">购物车</a>--%>
    <div class="fr closing" ><a class="fr closing" id="#" href="/untitled01_war_exploded/index.jsp">退出</a></div>
    <div class="fr total"><span id="priceTotal"></span></div>
    <div class="fr selected" id="selected">
<%--        <span id="selectedTotal">0</span>件--%>
<%--        <span class="arrow up">︽</span>--%>
<%--        <span class="arrow down">︾</span>--%>
        <a class="fl delete" id="deleeAll" >购物车</a>
<%--        <span class="fl delete" id="deleeAll" onclick="add()">购物车</span>/untitled01_war_exploded/JSP/Shopping.jsp--%>
    </div>
    <div class="selected-view">
        <div id="selectedViewList" class="clearfix">
            <!--<div><img src="images/1.jpg"><span>取消选择</span></div>-->
        </div>
        <span class="arrow">◆<span>◆</span></span>
    </div>
</div>
<table id="cartTable">
    <thead>
    <tr>
        <th>序号</th>
        <th>商品</th>
        <th>单价</th>
        <th>详情</th>

        <th>操作</th>
    </tr>
    </thead>
    <tbody id="number">
    <tr>
        <td class="checkbox"></td>
        <td class="goods"><img src="/untitled01_war_exploded/images/1-1.jpg" alt="" id="img1"/><span id="name1">Casio/卡西欧 EX-TR350</span></td>
        <td class="price" id="td1">5999.88</td>
        <td class="count">
            D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run
            [2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to start
            Using CATALINA_BASE:   "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\
            Using CATALINA_HOME:   "D:\TOMCAT\apache-tomcat-8.5.85"
            Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"
            </td>
        <td class="operation"><span class="delete" onclick="proAdd(img1,name1,td1)">加入购物车</span></td>
    </tr>
    <tr>
        <td class="checkbox"></td>
        <td class="goods"><img src="/untitled01_war_exploded/images/1-2.jpg" alt="" id="img2"/><span id="name2">Canon/佳能 PowerShot SX50 HS</span></td>
        <td class="price" id="td2" >3888.50</td>
        <td class="count">
            D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run
            [2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to start
            Using CATALINA_BASE:   "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\
            Using CATALINA_HOME:   "D:\TOMCAT\apache-tomcat-8.5.85"
            Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"
        </td>
        <td class="operation"><span class="delete" onclick="proAdd(img2,name2,td2)">加入购物车</span></td>
    </tr>
    <tr>
        <td class="checkbox"></td>
        <td class="goods"><img src="/untitled01_war_exploded/images/1-3.jpg" alt="" id="img3"/><span id="name3">Sony/索尼 DSC-WX300</span></td>
        <td class="price" id="td3">1428.50</td>
        <td class="count">
            D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run
            [2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to start
            Using CATALINA_BASE:   "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\
            Using CATALINA_HOME:   "D:\TOMCAT\apache-tomcat-8.5.85"
            Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"
        </td>
        <td class="operation"><span class="delete" onclick="proAdd(img3,name3,td3)">加入购物车</span></td>
    </tr>
    <tr>
        <td class="checkbox"></td>
        <td class="goods"><img src="/untitled01_war_exploded/images/1-4.jpg" alt="" id="img4"/><span id="name4">Fujifilm/富士 instax mini 25</span></td>
        <td class="price" id="td4">640.60</td>
        <td class="count">
            D:\TOMCAT\apache-tomcat-8.5.85\bin\catalina.bat run
            [2023-01-31 03:58:08,262] Artifact untitled01: Waiting for server connection to start
            Using CATALINA_BASE:   "C:\Users\JIAHANG\AppData\Local\JetBrains\IntelliJIdea2022.3\
            Using CATALINA_HOME:   "D:\TOMCAT\apache-tomcat-8.5.85"
            Using CATALINA_TMPDIR: "D:\TOMCAT\apache-tomcat-8.5.85\temp"
        </td>
        <td class="operation"><span class="delete" onclick="proAdd(img4,name4,td4)">加入购物车</span></td>
    </tr>
    </tbody>
</table>
<%--<a href="././JSP/Shopping.jsp">购物车</a>--%>
    <%
     int userid = (int) request.getAttribute("userId");
    %>
<script type="text/javascript">
    const userid = "<%=userid%>";
    function proAdd(src,name,price1){
        //const img1 = document.getElementById(src);
        const src1 =  src.getAttribute("src")
        //const imgname = document.getElementById(name);
        const nametext =  name.innerText;
        //const pric = document.getElementById(price1);
        const price =  price1.innerText;
        //alert(src1+nametext+price);
        let params="src1="+encodeURIComponent(src1)+"&name1="+encodeURIComponent(nametext)+"&price="+encodeURIComponent(price)+"&userid="+encodeURIComponent(userid);
        //提交数据
        var myrequest  = new XMLHttpRequest();
        myrequest.open("post","/untitled01_war_exploded/ProductServlet",true)

        myrequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        myrequest.send(params);
        //查看状态码提示,我还是调用登录时的信息弹框
        myrequest.onreadystatechange = function () {
            if(myrequest.readyState===4){
                 let msg = myrequest.responseText
                displayAlert("success",msg,1500)
                //alert(myrequest.responseText);
            }

        };


    };
    var d =  document.getElementById("deleeAll");
    d.onclick = function() {
        //let uid = "uid";
        let path = "ToShoppingServlet";
        let list ={"userid":userid}
        formaction(path,list)

        // window.location.replace('http://localhost:8080/untitled01_war_exploded/JSP/Shopping.jsp');
        // document.write("<form action=ToShoppingServlet method=post name=form1 style='display:none'>");
        // document.write("<input type=hidden name=userid value='"+userid+"'/>");
        // document.write("</form>");
        // document.form1.submit();

        //提交数据
        //let params="userid="+encodeURIComponent(userid);
        // var myrequest  = new XMLHttpRequest();
        // myrequest.open("post","/untitled01_war_exploded/ToShoppingServlet",true)
        // myrequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        // myrequest.send(params);
        // //查看状态码提示,我还是调用登录时的信息弹框
        // myrequest.onreadystatechange = function () {
        //     //console.log(myrequest.getResponseHeader("REQUEST_AUTH"))
        //     if(myrequest.readyState===4){
        //
        //
        //         // if(myrequest.getResponseHeader("REQUEST_AUTH") == 1){
        //         //     window.location.href = '/untitled01_war_exploded/JSP/Shopping.jsp?userid='+userid;
        //         // }
        //     }
        //
        // };
    }


</script>
</body>

</html>
